﻿Imports System.Data
Imports System.Data.SqlClient

Imports BusinessLogicLayer
Imports BE = BusinessEntities

Partial Class RegistrarRequisicion
    Inherits System.Web.UI.Page
    Dim dlb_cantpersona As Integer
    Dim dlb_totalpersonas As Integer
    Dim v01 As Integer
    Dim v02 As Integer
    Dim v03 As Integer
    Dim v04 As Integer
    Dim v05 As Integer
    Dim v06 As Integer
    Dim str_parametro As String
    Dim str_error As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            CargarServicio()
            CargarTecnologia()
            CargarCargos()
        End If
        Dim usu As Integer
        Dim responNom, responApe As String
        str_parametro = Request.QueryString("par")
        usu = Session("USUARIO")

        Dim capanegociosR As New RequisicionBL
        Dim capanegociosU As New UsuarioBL
        Dim objetoproyecto As New BE.ProyectoDTO
        Dim objetousuario As New BE.UsuarioDTO
        Dim ds1, ds2 As New DataSet

        txtFecha.Text = Date.Now
        txtNRequisicion.Text = capanegociosR.recuperarMaximoRequirimiento
        ' se busca los datos del usuario
        objetousuario.CodigoUsuario = usu
        'se busca los datos del proyecto
        objetoproyecto.CodigoProyecto = str_parametro
        Try
            ds1 = capanegociosR.DATA_REQUESICION(objetoproyecto)
            ds2 = capanegociosU.BuscarUsuario(objetousuario)

            txtOV.Text = ds1.Tables("DATA_REQUISICION").Rows(0).Item("NRO_ORD_VEN")
            txtCliente.Text = ds1.Tables("DATA_REQUISICION").Rows(0).Item("NOM_CLI")
            txtEtapa.Text = ds1.Tables("DATA_REQUISICION").Rows(0).Item("NOM_ETA_PRY")
            txtProyecto.Text = ds1.Tables("DATA_REQUISICION").Rows(0).Item("NOM_PRY")

            responNom = ds2.Tables("BuscarUsuario").Rows(0).Item("NOM_USU")
            responApe = ds2.Tables("BuscarUsuario").Rows(0).Item("APE_USU")
            txtResponsable.Text = responNom + " " + responApe

        Catch ex As Exception
            Dim str_error As String
            str_error = capanegociosR.CapturaError
            Response.Redirect("Errores.aspx?par=" & str_error & ex.Message)
        End Try
        txtTotRequirimiento.Text = TotalRequisicion()
    End Sub

    Sub CargarServicio()
        Dim capanegocios As New RequisicionBL
        Try
            With ddlServicio
                .DataSource = capanegocios.ListarServicios
                .DataValueField = "COD_SER"
                .DataTextField = "NOM_SER"
                .DataBind()
            End With
        Catch ex As Exception
            Dim str_error As String
            str_error = capanegocios.CapturaError
            Response.Redirect("Errores.aspx?par=" & str_error)
        Finally
            capanegocios = Nothing
        End Try
    End Sub
    Sub CargarTecnologia()
        Dim capanegocios As New RequisicionBL
        Try
            With ddlTecnologia
                .DataSource = capanegocios.ListarTecnologia
                .DataValueField = "COD_TEC"
                .DataTextField = "NOM_TEC"
                .DataBind()
            End With
        Catch ex As Exception
            Dim str_error As String
            str_error = capanegocios.CapturaError
            Response.Redirect("Errores.aspx?par=" & str_error)
        Finally
            capanegocios = Nothing
        End Try
    End Sub
    'ALIMENTACION
    Protected Sub btnMoviAumMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoviAumMotiv.Click
        txtmotmov4.Visible() = True
        txtmotmov5.Visible() = True
        txtpremov4.Visible() = True
        txtpremov5.Visible() = True
    End Sub
    Protected Sub btnMoviQuiMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoviQuiMotiv.Click
        txtmotmov4.Visible() = False
        txtmotmov5.Visible() = False
        txtpremov4.Visible() = False
        txtpremov5.Visible() = False
        txtmotmov4.Text = "Digite descrip. de gasto"
        txtmotmov5.Text = "Digite descrip. de gasto"
        txtpremov4.Text = 0
        txtpremov5.Text = 0
    End Sub
    Protected Sub btnPetroAumMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPetroAumMotiv.Click
        txtmotpet4.Visible() = True
        txtmotpet5.Visible() = True
        txtprepet4.Visible() = True
        txtprepet5.Visible() = True
    End Sub
    Protected Sub btnPetroQuiMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPetroQuiMotiv.Click
        txtmotpet4.Visible() = False
        txtmotpet5.Visible() = False
        txtprepet4.Visible() = False
        txtprepet5.Visible() = False
        txtmotpet4.Text = "Digite descrip. de gasto"
        txtmotpet5.Text = "Digite descrip. de gasto"
        txtprepet4.Text = 0
        txtprepet5.Text = 0
    End Sub
    Protected Sub btnPasAumMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPasAumMotiv.Click
        txtmotpas4.Visible() = True
        txtmotpas5.Visible() = True
        txtprepas4.Visible() = True
        txtprepas5.Visible() = True
    End Sub
    Protected Sub btnPasQuiMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPasQuiMotiv.Click
        txtmotpas4.Visible() = False
        txtmotpas5.Visible() = False
        txtprepas4.Visible() = False
        txtprepas5.Visible() = False
        txtmotpas4.Text = "Digite descrip. de gasto"
        txtmotpas5.Text = "Digite descrip. de gasto"
        txtprepas4.Text = 0
        txtprepas5.Text = 0
    End Sub
    Protected Sub btnFleteAumMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFleteAumMotiv.Click
        txtmotfle4.Visible() = True
        txtmotfle5.Visible() = True
        txtprefle4.Visible() = True
        txtprefle5.Visible() = True
    End Sub
    Protected Sub btnFleteQuiMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFleteQuiMotiv.Click
        txtmotfle4.Visible() = False
        txtmotfle5.Visible() = False
        txtprefle4.Visible() = False
        txtprefle5.Visible() = False
        txtmotfle4.Text = "Digite descrip. de gasto"
        txtmotfle5.Text = "Digite descrip. de gasto"
        txtprefle4.Text = 0
        txtprefle5.Text = 0
    End Sub
    Protected Sub btnHerraAumMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHerraAumMotiv.Click
        txtmotherr4.Visible() = True
        txtmotherr5.Visible() = True
        txtpreherr4.Visible() = True
        txtpreherr5.Visible() = True
    End Sub
    Protected Sub btnHerraQuiMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHerraQuiMotiv.Click
        txtmotherr4.Visible() = False
        txtmotherr5.Visible() = False
        txtpreherr4.Visible() = False
        txtpreherr5.Visible() = False
        txtmotherr4.Text = "Digite descrip. de gasto"
        txtmotherr5.Text = "Digite descrip. de gasto"
        txtpreherr4.Text = 0
        txtpreherr5.Text = 0
    End Sub
    Protected Sub btnOtroAumMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOtroAumMotiv.Click
        txtmototros4.Visible() = True
        txtmototros5.Visible() = True
        txtpreotros4.Visible() = True
        txtpreotros5.Visible() = True
    End Sub
    Protected Sub btnOtroQuiMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOtroQuiMotiv.Click
        txtmototros4.Visible() = False
        txtmototros5.Visible() = False
        txtpreotros4.Visible() = False
        txtpreotros5.Visible() = False
        txtmototros4.Text = "Digite descrip. de gasto"
        txtmototros5.Text = "Digite descrip. de gasto"
        txtpreotros4.Text = 0
        txtpreotros5.Text = 0
    End Sub
    Protected Sub btnPersAumMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPersAumMotiv.Click
        ddlCargoPers4.Visible = True
        ddlCargoPers5.Visible = True
        ddlCargoPers6.Visible = True
        txtCantPers4.Visible = True
        txtCantPers4.Visible = True
        txtCantPers5.Visible = True
        txtCantPers6.Visible = True
        txtDiasxPersona4.Visible = True
        txtDiasxPersona5.Visible = True
        txtDiasxPersona6.Visible = True
        txtPagUniPers4.Visible = True
        txtPagUniPers5.Visible = True
        txtPagUniPers6.Visible = True
    End Sub

    Protected Sub btnPersQuiMotiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPersQuiMotiv.Click
        ddlCargoPers4.Visible = False
        ddlCargoPers5.Visible = False
        ddlCargoPers6.Visible = False
        txtCantPers4.Visible = False
        txtCantPers4.Visible = False
        txtCantPers5.Visible = False
        txtCantPers6.Visible = False
        txtDiasxPersona4.Visible = False
        txtDiasxPersona5.Visible = False
        txtDiasxPersona6.Visible = False
        txtPagUniPers4.Visible = False
        txtPagUniPers5.Visible = False
        txtPagUniPers6.Visible = False

        'ddlCargoPers4.SelectedIndex = 0
        'ddlCargoPers5.SelectedIndex = 0
        'ddlCargoPers6.SelectedIndex = 0
        txtCantPers4.Text = "0"
        txtCantPers5.Text = "0"
        txtCantPers6.Text = "0"
        txtDiasxPersona4.Text = "0"
        txtDiasxPersona5.Text = "0"
        txtDiasxPersona6.Text = "0"
        txtPagUniPers4.Text = "0"
        txtPagUniPers5.Text = "0"
        txtPagUniPers6.Text = "0"
    End Sub
    'ALIMENTOS
    Protected Sub btnAlimCalcu_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAlimCalcu.Click
        If String.IsNullOrEmpty(txtAlimCantDias.Text) Then
            txtAlimCantDias.Text = "0"
        End If
        If String.IsNullOrEmpty(txtAlimCantPers.Text) Then
            txtAlimCantPers.Text = "0"
        End If
        txtAlimSubTotal.Text = ObtenerPrecioscbo(txtAlimCantDias.Text, txtAlimCantPers.Text, ddlAlimGastoPerso.SelectedValue)
        txtVerAlim.Text = ObtenerPrecioscbo(txtAlimCantDias.Text, txtAlimCantPers.Text, ddlAlimGastoPerso.SelectedValue)
        txtTotRequirimiento.Text = TotalRequisicion()


        dlb_cantpersona = Integer.Parse(txtAlimCantPers.Text)
        dlb_totalpersonas = Integer.Parse(txtTotPersonas.Text)

        dlb_totalpersonas = dlb_cantpersona + dlb_totalpersonas

        txtTotPersonas.Text = dlb_totalpersonas
        dlb_cantpersona = 0




    End Sub
    'ALOJAMIENTO
    Protected Sub btnAlojCalcu_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAlojCalcu.Click
        If String.IsNullOrEmpty(txtAlojCantDias.Text) Then
            txtAlojCantDias.Text = "0"
        End If

        If String.IsNullOrEmpty(txtAlojCantPerso.Text) Then
            txtAlojCantPerso.Text = "0"
        End If
        txtAlojSubTotal.Text = ObtenerPrecioscbo(txtAlojCantDias.Text, txtAlojCantPerso.Text, ddlAlojGastoPerso.SelectedValue)
        txtVerAloj.Text = ObtenerPrecioscbo(txtAlojCantDias.Text, txtAlojCantPerso.Text, ddlAlojGastoPerso.SelectedValue)
        txtTotRequirimiento.Text = TotalRequisicion()
        dlb_cantpersona = Integer.Parse(txtAlojCantPerso.Text)
        dlb_totalpersonas = Integer.Parse(txtTotPersonas.Text)

        dlb_totalpersonas = dlb_cantpersona + dlb_totalpersonas

        txtTotPersonas.Text = dlb_totalpersonas
        dlb_cantpersona = 0







    End Sub
    'PERSONAL
    Protected Sub btnPersCalcular_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPersCalcular.Click

        If String.IsNullOrEmpty(txtCantPers1.Text) Then
            txtCantPers1.Text = "0"
        End If
        If String.IsNullOrEmpty(txtCantPers2.Text) Then
            txtCantPers2.Text = "0"
        End If
        If String.IsNullOrEmpty(txtCantPers3.Text) Then
            txtCantPers3.Text = "0"
        End If
        If String.IsNullOrEmpty(txtCantPers4.Text) Then
            txtCantPers4.Text = "0"
        End If
        If String.IsNullOrEmpty(txtCantPers5.Text) Then
            txtCantPers5.Text = "0"
        End If
        If String.IsNullOrEmpty(txtCantPers6.Text) Then
            txtCantPers6.Text = "0"
        End If
        If String.IsNullOrEmpty(txtPagUniPers1.Text) Then
            txtPagUniPers1.Text = "0"
        End If
        If String.IsNullOrEmpty(txtPagUniPers2.Text) Then
            txtPagUniPers2.Text = "0"
        End If
        If String.IsNullOrEmpty(txtPagUniPers3.Text) Then
            txtPagUniPers3.Text = "0"
        End If
        If String.IsNullOrEmpty(txtPagUniPers4.Text) Then
            txtPagUniPers4.Text = "0"
        End If

        If String.IsNullOrEmpty(txtPagUniPers5.Text) Then
            txtPagUniPers5.Text = "0"
        End If
        If String.IsNullOrEmpty(txtPagUniPers6.Text) Then
            txtPagUniPers6.Text = "0"
        End If
        If (ddlCargoPers1.Text.Equals("Externo por dias")) Then
            txtVerPerso.Text = _
            Integer.Parse(txtCantPers1.Text) * Integer.Parse(txtDiasxPersona1.Text) * Double.Parse(txtPagUniPers1.Text) + _
            Integer.Parse(txtCantPers2.Text) * Integer.Parse(txtDiasxPersona2.Text) * Double.Parse(txtPagUniPers2.Text) + _
            Integer.Parse(txtCantPers3.Text) * Integer.Parse(txtDiasxPersona3.Text) * Double.Parse(txtPagUniPers3.Text) + _
            Integer.Parse(txtCantPers4.Text) * Integer.Parse(txtDiasxPersona4.Text) * Double.Parse(txtPagUniPers4.Text) + _
            Integer.Parse(txtCantPers5.Text) * Integer.Parse(txtDiasxPersona5.Text) * Double.Parse(txtPagUniPers5.Text) + _
            Integer.Parse(txtCantPers6.Text) * Integer.Parse(txtDiasxPersona6.Text) * Double.Parse(txtPagUniPers6.Text)
        Else
            txtVerPerso.Text = Integer.Parse(txtCantPers1.Text) * Double.Parse(txtPagUniPers1.Text) + _
                           Integer.Parse(txtCantPers2.Text) * Double.Parse(txtPagUniPers2.Text) + _
                           Integer.Parse(txtCantPers3.Text) * Double.Parse(txtPagUniPers3.Text) + _
                           Integer.Parse(txtCantPers4.Text) * Double.Parse(txtPagUniPers4.Text) + _
                           Integer.Parse(txtCantPers5.Text) * Double.Parse(txtPagUniPers5.Text) + _
                           Integer.Parse(txtCantPers6.Text) * Double.Parse(txtPagUniPers6.Text)

        End If


        txtTotRequirimiento.Text = TotalRequisicion()


        v01 = Integer.Parse(txtCantPers1.Text)
        v02 = Integer.Parse(txtCantPers2.Text)
        v03 = Integer.Parse(txtCantPers3.Text)
        v04 = Integer.Parse(txtCantPers4.Text)
        v05 = Integer.Parse(txtCantPers5.Text)
        v06 = Integer.Parse(txtCantPers6.Text)



        dlb_totalpersonas = Integer.Parse(txtTotPersonas.Text)

        dlb_totalpersonas = v01 + v02 + v03 + v04 + v05 + v06 + dlb_totalpersonas

        txtTotPersonas.Text = dlb_totalpersonas

        v01 = 0
        v02 = 0
        v03 = 0
        v04 = 0
        v05 = 0
        v06 = 0



    End Sub
    'MOVILIDAD
    Protected Sub btnMoviCalcular_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoviCalcular.Click
        txtVerMovil.Text = ObtenerPreciossincbo(txtpremov1.Text, txtpremov2.Text, txtpremov3.Text, txtpremov4.Text, txtpremov5.Text)
        txtTotRequirimiento.Text = TotalRequisicion()
    End Sub
    'PETROLEO
    Protected Sub btnPetroCalcular_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPetroCalcular.Click
        txtVerPetrol.Text = ObtenerPreciossincbo(txtprepet1.Text, txtprepet2.Text, txtprepet3.Text, txtprepet4.Text, txtprepet5.Text)
        txtTotRequirimiento.Text = TotalRequisicion()
    End Sub
    'PASAJES
    Protected Sub btnPasajCalcular_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPasajCalcular.Click
        txtVerPasaj.Text = ObtenerPreciossincbo(txtprepas1.Text, txtprepas2.Text, txtprepas3.Text, txtprepas4.Text, txtprepas5.Text)
        txtTotRequirimiento.Text = TotalRequisicion()
    End Sub
    'FLETES
    Protected Sub btnFleteCalcular_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFleteCalcular.Click
        txtVerFletes.Text = ObtenerPreciossincbo(txtprefle1.Text, txtprefle2.Text, txtprefle3.Text, txtprefle4.Text, txtprefle5.Text)
        txtTotRequirimiento.Text = TotalRequisicion()
    End Sub
    'HERRAMIENTAS
    Protected Sub btnHerraCalcular_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHerraCalcular.Click
        txtVerHerram.Text = ObtenerPreciossincbo(txtpreherr1.Text, txtpreherr2.Text, txtpreherr3.Text, txtpreherr4.Text, txtpreherr5.Text)
        txtTotRequirimiento.Text = TotalRequisicion()
    End Sub
    'OTROS
    Protected Sub btnOtroCalcular_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOtroCalcular.Click
        txtVerOtros.Text = ObtenerPreciossincbo(txtpreotros1.Text, txtpreotros2.Text, txtpreotros3.Text, txtpreotros4.Text, txtpreotros5.Text)
        txtTotRequirimiento.Text = TotalRequisicion()
    End Sub

    Protected Sub btnGrabarRequisicion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGrabarRequisicion.Click
        Dim negocioRequisicion As New RequisicionBL
        Dim negocioAdicional As New AdicionalesBL
        Dim beanAdicional As New BE.AdicionalesDTO
        negocioRequisicion.InsertarRequisicion(cargarRequisicion())
        'BEAN_ALIMENTOS
        With beanAdicional
            .Numero_Requisicion = txtNRequisicion.Text.Trim
            .Codigo_Gasto = 1
            .Motivo_Adicional = ""
            .Fecha_Inicio = txtFec_Ini.Text
            .Fecha_Fin = txtFec_Fin.Text
            .Numero_Personas = txtAlimCantPers.Text.Trim
            .Numero_Dias = txtAlimCantDias.Text.Trim
            .Costo_Persona = ddlAlimGastoPerso.SelectedValue
            .Observaciones_Add = ""
            .Sub_Total = txtAlimSubTotal.Text.Trim
        End With
        Try
            If Not beanAdicional.Sub_Total = 0 Then
                negocioAdicional.InsertarAdicional(beanAdicional)
            End If
        Catch ex As Exception
            Dim str_error As String
            str_error = negocioAdicional.CapturaError
            Response.Redirect("Errores.aspx?par=" & str_error)
        End Try

        'BEAN_ALOJAMIENTO
        With beanAdicional
            .Numero_Requisicion = txtNRequisicion.Text.Trim
            .Codigo_Gasto = 2
            .Motivo_Adicional = ""
            .Fecha_Inicio = txtFec_Ini.Text
            .Fecha_Fin = txtFec_Fin.Text
            .Numero_Personas = txtAlojCantPerso.Text.Trim
            .Numero_Dias = txtAlojCantDias.Text.Trim
            .Costo_Persona = ddlAlojGastoPerso.SelectedValue
            .Observaciones_Add = ""
            .Sub_Total = txtAlojSubTotal.Text.Trim
        End With
        Try
            If Not beanAdicional.Sub_Total = 0 Then
                negocioAdicional.InsertarAdicional(beanAdicional)
            End If
        Catch ex As Exception
            Dim str_error As String
            str_error = negocioAdicional.CapturaError
            Response.Redirect("Errores.aspx?par=" & str_error)
        End Try
        'BEAN_PERSONA
        'With beanAdicional
        '    .Numero_Requisicion = txtNRequisicion.Text.Trim
        '    .Codigo_Gasto = 3
        '    .Motivo_Adicional = ""
        '    .Fecha_Inicio = txtFec_Ini.Text
        '    .Fecha_Fin = txtFec_Fin.Text
        '    .Numero_Personas = txtCantPers1.Text.Trim
        '    .Numero_Dias = txtPersCantDias.Text.Trim
        '    .Costo_Persona = ddlPersoGastoPerso.SelectedValue
        '    .Observaciones_Add = ""
        '    .Sub_Total = txtPersSubTotal.Text.Trim
        'End With
        'Try
        '    If Not beanAdicional.Sub_Total = 0 Then
        '        negocioAdicional.InsertarAdicional(beanAdicional)
        '    End If
        'Catch ex As Exception
        '    Dim str_error As String
        '    str_error = negocioAdicional.CapturaError
        '    Response.Redirect("Errores.aspx?par=" & str_error)
        'End Try

        For i As Integer = 0 To ObtenerCargosPersonal(ddlCargoPers1.Text, ddlCargoPers2.Text, ddlCargoPers3.Text, _
                                    ddlCargoPers4.Text, ddlCargoPers5.Text, ddlCargoPers6.Text).Count - 1

            'EVITAR CARGOS NULOS
            If Not (ObtenerCargosPersonal(ddlCargoPers1.Text, ddlCargoPers2.Text, ddlCargoPers3.Text, _
                    ddlCargoPers4.Text, ddlCargoPers5.Text, ddlCargoPers6.Text)(i).Equals("0") Or _
                    String.IsNullOrEmpty(ObtenerCargosPersonal(ddlCargoPers1.Text, ddlCargoPers2.Text, _
                                         ddlCargoPers3.Text, ddlCargoPers4.Text, ddlCargoPers5.Text, _
                                         ddlCargoPers6.Text)(i))) Then
                'EVITAR CANTIDADES NULAS
                If Not (ObtenerCantidadPersonal(txtCantPers1.Text, txtCantPers2.Text, txtCantPers3.Text, _
                    txtCantPers4.Text, txtCantPers5.Text, txtCantPers6.Text)(i).Equals("0") Or _
                    String.IsNullOrEmpty(ObtenerCantidadPersonal(txtCantPers1.Text, txtCantPers2.Text, _
                                         txtCantPers3.Text, txtCantPers4.Text, txtCantPers5.Text, _
                                         txtCantPers6.Text)(i))) Then
                    'EVITAR DIAS NULOS
                    If Not (ObtenerNroDiasPersonal(txtDiasxPersona1.Text, txtDiasxPersona2.Text, txtDiasxPersona3.Text, _
                   txtDiasxPersona4.Text, txtDiasxPersona5.Text, txtDiasxPersona6.Text)(i).Equals("0") Or _
                   String.IsNullOrEmpty(ObtenerNroDiasPersonal(txtDiasxPersona1.Text, txtDiasxPersona2.Text, _
                                        txtDiasxPersona3.Text, txtDiasxPersona4.Text, txtDiasxPersona5.Text, _
                                        txtDiasxPersona6.Text)(i))) Then
                        'EVITAR PAGOS NULOS
                        If Not (ObtenerPagoPersonal(txtPagUniPers1.Text, txtPagUniPers2.Text, txtPagUniPers3.Text, _
                   txtPagUniPers4.Text, txtPagUniPers5.Text, txtPagUniPers6.Text)(i).Equals("0") Or _
                   String.IsNullOrEmpty(ObtenerPagoPersonal(txtPagUniPers1.Text, txtPagUniPers2.Text, _
                                        txtPagUniPers3.Text, txtPagUniPers4.Text, txtPagUniPers5.Text, _
                                        txtPagUniPers6.Text)(i))) Then
                            With beanAdicional
                                .Numero_Requisicion = txtNRequisicion.Text.Trim
                                .Codigo_Gasto = 4
                                .Motivo_Adicional = ""
                                .Fecha_Inicio = txtFec_Ini.Text
                                .Fecha_Fin = txtFec_Fin.Text
                                .Numero_Personas = _
                                ObtenerCantidadPersonal(txtCantPers1.Text, txtCantPers2.Text, txtCantPers3.Text, _
                                                        txtCantPers4.Text, txtCantPers5.Text, txtCantPers6.Text)(i)
                                .Numero_Dias = _
                                ObtenerNroDiasPersonal(txtPagUniPers1.Text, txtPagUniPers2.Text, txtPagUniPers3.Text, _
                                                       txtPagUniPers4.Text, txtPagUniPers5.Text, txtPagUniPers6.Text)(i)
                                .Costo_Persona = _
                                ObtenerPagoPersonal(txtPagUniPers1.Text, txtPagUniPers2.Text, txtPagUniPers3.Text, _
                                                    txtPagUniPers4.Text, txtPagUniPers5.Text, txtPagUniPers6.Text)(i)
                                .Observaciones_Add = _
                                ObtenerCargosPersonal(ddlCargoPers1.Text, ddlCargoPers2.Text, ddlCargoPers3.Text, _
                                                      ddlCargoPers4.Text, ddlCargoPers5.Text, ddlCargoPers6.Text)(i)
                                .Sub_Total = txtVerMovil.Text.Trim
                            End With
                        Else
                            Continue For
                        End If
                    Else
                        Continue For
                    End If
                Else
                    Continue For
                End If
            Else
                Continue For
            End If
            'GRABAR BEAN
            negocioAdicional.InsertarAdicional(beanAdicional)
        Next

        'BEAN_MOVILIDAD
        For i As Integer = 0 To ObtenerMotivos(txtmotmov1.Text, txtmotmov2.Text, txtmotmov3.Text, txtmotmov4.Text, txtmotmov5.Text).Count - 1

            'EVITAR MOTIVOS NULOS
            If Not (ObtenerMotivos(txtmotmov1.Text, txtmotmov2.Text, txtmotmov3.Text, txtmotmov4.Text, _
                        txtmotmov5.Text)(i).Equals("Digite descrip. de gasto") Or _
                        String.IsNullOrEmpty(ObtenerMotivos(txtmotmov1.Text, txtmotmov2.Text, _
                                                     txtmotmov3.Text, txtmotmov4.Text, _
                                                        txtmotmov5.Text)(i))) Then
                'EVITAR PRECIOS NULOS
                If Not (ObtenerPrecios(txtpremov1.Text, txtpremov2.Text, txtpremov3.Text, txtpremov4.Text, _
                    txtpremov5.Text)(i) = 0 Or _
                    String.IsNullOrEmpty(ObtenerPrecios(txtpremov1.Text, txtpremov2.Text, _
                                                 txtpremov3.Text, txtpremov4.Text, _
                                                    txtpremov5.Text)(i))) Then
                    With beanAdicional
                        .Numero_Requisicion = txtNRequisicion.Text.Trim
                        .Codigo_Gasto = 4
                        .Motivo_Adicional = ""
                        .Fecha_Inicio = txtFec_Ini.Text
                        .Fecha_Fin = txtFec_Fin.Text
                        .Numero_Personas = 0
                        .Numero_Dias = 0
                        .Costo_Persona = _
                        ObtenerPrecios(txtpremov1.Text, txtpremov2.Text, txtpremov3.Text, _
                                       txtpremov4.Text, txtpremov5.Text)(i)
                        .Observaciones_Add = _
                        ObtenerMotivos(txtmotmov1.Text, txtmotmov2.Text, txtmotmov3.Text, _
                                txtmotmov4.Text, txtmotmov5.Text)(i)
                        .Sub_Total = txtVerMovil.Text.Trim
                    End With
                Else
                    Continue For
                End If
            Else
                Continue For
            End If
            'GRABAR BEAN
            negocioAdicional.InsertarAdicional(beanAdicional)
        Next

        'BEAN_PETROLEO
        For i As Integer = 0 To ObtenerMotivos(txtmotpet1.Text, txtmotpet2.Text, txtmotpet3.Text, txtmotpet4.Text, txtmotpet5.Text).Count - 1
            'EVITAR MOTIVOS NULOS
            If Not (ObtenerMotivos(txtmotpet1.Text, txtmotpet2.Text, txtmotpet3.Text, txtmotpet4.Text, _
                        txtmotpet5.Text)(i).Equals("Digite descrip. de gasto") Or _
                        String.IsNullOrEmpty(ObtenerMotivos(txtmotpet1.Text, txtmotpet2.Text, _
                                                     txtmotpet3.Text, txtmotpet4.Text, _
                                                        txtmotpet5.Text)(i))) Then
                'EVITAR PRECIOS NULOS
                If Not (ObtenerPrecios(txtprepet1.Text, txtprepet2.Text, txtprepet3.Text, txtprepet4.Text, _
                    txtprepet5.Text)(i) = 0 Or _
                    String.IsNullOrEmpty(ObtenerPrecios(txtprepet1.Text, txtprepet2.Text, _
                                                 txtprepet3.Text, txtprepet4.Text, _
                                                    txtprepet5.Text)(i))) Then
                    With beanAdicional
                        .Numero_Requisicion = txtNRequisicion.Text.Trim
                        .Codigo_Gasto = 5
                        .Motivo_Adicional = ""
                        .Fecha_Inicio = txtFec_Ini.Text
                        .Fecha_Fin = txtFec_Fin.Text
                        .Numero_Personas = 0
                        .Numero_Dias = 0
                        .Costo_Persona = _
                        ObtenerPrecios(txtprepet1.Text, txtprepet2.Text, txtprepet3.Text, _
                                       txtprepet4.Text, txtprepet5.Text)(i)
                        .Observaciones_Add = _
                        ObtenerMotivos(txtmotpet1.Text, txtmotpet2.Text, txtmotpet3.Text, _
                                txtmotpet4.Text, txtmotpet5.Text)(i)
                        .Sub_Total = txtVerPetrol.Text.Trim
                    End With
                Else
                    Continue For
                End If
            Else
                Continue For
            End If
            'GRABAR BEAN
            negocioAdicional.InsertarAdicional(beanAdicional)
        Next

        'BEAN_PASAJES
        For i As Integer = 0 To ObtenerMotivos(txtmotpas1.Text, txtmotpas2.Text, txtmotpas3.Text, txtmotpas4.Text, txtmotpas5.Text).Count - 1
            'EVITAR MOTIVOS NULOS
            If Not (ObtenerMotivos(txtmotpas1.Text, txtmotpas2.Text, txtmotpas3.Text, txtmotpas4.Text, _
                        txtmotpas5.Text)(i).Equals("Digite descrip. de gasto") Or _
                        String.IsNullOrEmpty(ObtenerMotivos(txtmotpas1.Text, txtmotpas2.Text, _
                                                     txtmotpas3.Text, txtmotpas4.Text, _
                                                        txtmotpas5.Text)(i))) Then
                'EVITAR PRECIOS NULOS
                If Not (ObtenerPrecios(txtprepas1.Text, txtprepas2.Text, txtprepas3.Text, txtprepas4.Text, _
                    txtprepas5.Text)(i) = 0 Or _
                    String.IsNullOrEmpty(ObtenerPrecios(txtprepas1.Text, txtprepas2.Text, _
                                                 txtprepas3.Text, txtprepas4.Text, _
                                                    txtprepas5.Text)(i))) Then
                    With beanAdicional
                        .Numero_Requisicion = txtNRequisicion.Text.Trim
                        .Codigo_Gasto = 6
                        .Motivo_Adicional = ""
                        .Fecha_Inicio = txtFec_Ini.Text
                        .Fecha_Fin = txtFec_Fin.Text
                        .Numero_Personas = 0
                        .Numero_Dias = 0
                        .Costo_Persona = _
                        ObtenerPrecios(txtprepas1.Text, txtprepas2.Text, txtprepas3.Text, _
                                       txtprepas4.Text, txtprepas5.Text)(i)
                        .Observaciones_Add = _
                        ObtenerMotivos(txtmotpas1.Text, txtmotpas2.Text, txtmotpas3.Text, _
                                txtmotpas4.Text, txtmotpas5.Text)(i)
                        .Sub_Total = txtVerPasaj.Text.Trim
                    End With
                Else
                    Continue For
                End If
            Else
                Continue For
            End If
            'GRABAR BEAN
            negocioAdicional.InsertarAdicional(beanAdicional)
        Next

        'BEAN_FLETES
        For i As Integer = 0 To ObtenerMotivos(txtmotfle1.Text, txtmotfle2.Text, txtmotfle3.Text, txtmotfle4.Text, txtmotfle5.Text).Count - 1
            'EVITAR MOTIVOS NULOS
            If Not (ObtenerMotivos(txtmotfle1.Text, txtmotfle2.Text, txtmotfle3.Text, txtmotfle4.Text, _
                        txtmotfle5.Text)(i).Equals("Digite descrip. de gasto") Or _
                        String.IsNullOrEmpty(ObtenerMotivos(txtmotfle1.Text, txtmotfle2.Text, _
                                                     txtmotfle3.Text, txtmotfle4.Text, _
                                                        txtmotfle5.Text)(i))) Then
                'EVITAR PRECIOS NULOS
                If Not (ObtenerPrecios(txtprefle1.Text, txtprefle2.Text, txtprefle3.Text, txtprefle4.Text, _
                    txtprefle5.Text)(i) = 0 Or _
                    String.IsNullOrEmpty(ObtenerPrecios(txtprefle1.Text, txtprefle2.Text, _
                                                 txtprefle3.Text, txtprefle4.Text, _
                                                    txtprefle5.Text)(i))) Then
                    With beanAdicional
                        .Numero_Requisicion = txtNRequisicion.Text.Trim
                        .Codigo_Gasto = 7
                        .Motivo_Adicional = ""
                        .Fecha_Inicio = txtFec_Ini.Text
                        .Fecha_Fin = txtFec_Fin.Text
                        .Numero_Personas = 0
                        .Numero_Dias = 0
                        .Costo_Persona = _
                        ObtenerPrecios(txtprefle1.Text, txtprefle2.Text, txtprefle3.Text, _
                                       txtprefle4.Text, txtprefle5.Text)(i)
                        .Observaciones_Add = _
                        ObtenerMotivos(txtmotfle1.Text, txtmotfle2.Text, txtmotfle3.Text, _
                                txtmotfle4.Text, txtmotfle5.Text)(i)
                        .Sub_Total = txtVerFletes.Text.Trim
                    End With
                Else
                    Continue For
                End If
            Else
                Continue For
            End If
            'GRABAR BEAN
            negocioAdicional.InsertarAdicional(beanAdicional)
        Next

        'BEAN_HERRAMIENTAS
        For i As Integer = 0 To ObtenerMotivos(txtmotherr1.Text, txtmotherr2.Text, txtmotherr3.Text, txtmotherr4.Text, txtmotherr5.Text).Count - 1
            'EVITAR MOTIVOS NULOS
            If Not (ObtenerMotivos(txtmotherr1.Text, txtmotherr2.Text, txtmotherr3.Text, txtmotherr4.Text, _
                        txtmotherr5.Text)(i).Equals("Digite descrip. de gasto") Or _
                        String.IsNullOrEmpty(ObtenerMotivos(txtmotherr1.Text, txtmotherr2.Text, _
                                                     txtmotherr3.Text, txtmotherr4.Text, _
                                                        txtmotherr5.Text)(i))) Then
                'EVITAR PRECIOS NULOS
                If Not (ObtenerPrecios(txtpreherr1.Text, txtpreherr2.Text, txtpreherr3.Text, txtpreherr4.Text, _
                    txtpreherr5.Text)(i) = 0 Or _
                    String.IsNullOrEmpty(ObtenerPrecios(txtpreherr1.Text, txtpreherr2.Text, _
                                                 txtpreherr3.Text, txtpreherr4.Text, _
                                                    txtpreherr5.Text)(i))) Then
                    With beanAdicional
                        .Numero_Requisicion = txtNRequisicion.Text.Trim
                        .Codigo_Gasto = 8
                        .Motivo_Adicional = ""
                        .Fecha_Inicio = txtFec_Ini.Text
                        .Fecha_Fin = txtFec_Fin.Text
                        .Numero_Personas = 0
                        .Numero_Dias = 0
                        .Costo_Persona = _
                        ObtenerPrecios(txtpreherr1.Text, txtpreherr2.Text, txtpreherr3.Text, _
                                       txtpreherr4.Text, txtpreherr5.Text)(i)
                        .Observaciones_Add = _
                        ObtenerMotivos(txtmotherr1.Text, txtmotherr2.Text, txtmotherr3.Text, _
                                txtmotherr4.Text, txtmotherr5.Text)(i)
                        .Sub_Total = txtVerHerram.Text.Trim
                    End With
                Else
                    Continue For
                End If
            Else
                Continue For
            End If
            'GRABAR BEAN
            negocioAdicional.InsertarAdicional(beanAdicional)
        Next

        'BEAN_OTROS
        For i As Integer = 1 To ObtenerMotivos(txtmototros1.Text, txtmototros2.Text, txtmototros3.Text, txtmototros4.Text, txtmototros5.Text).Count - 1
            'EVITAR MOTIVOS NULOS
            If Not (ObtenerMotivos(txtmototros1.Text, txtmototros2.Text, txtmototros3.Text, txtmototros4.Text, _
                        txtmototros5.Text)(i).Equals("Digite descrip. de gasto") Or _
                        String.IsNullOrEmpty(ObtenerMotivos(txtmototros1.Text, txtmototros2.Text, _
                                                     txtmototros3.Text, txtmototros4.Text, _
                                                        txtmototros5.Text)(i))) Then
                'EVITAR PRECIOS NULOS
                If Not (ObtenerPrecios(txtpreotros1.Text, txtpreotros2.Text, txtpreotros3.Text, txtpreotros4.Text, _
                    txtpreotros5.Text)(i) = 0 Or _
                    String.IsNullOrEmpty(ObtenerPrecios(txtpreotros1.Text, txtpreotros2.Text, _
                                                 txtpreotros3.Text, txtpreotros4.Text, _
                                                    txtpreotros5.Text)(i))) Then
                    With beanAdicional
                        .Numero_Requisicion = txtNRequisicion.Text.Trim
                        .Codigo_Gasto = 9
                        .Motivo_Adicional = ""
                        .Fecha_Inicio = txtFec_Ini.Text
                        .Fecha_Fin = txtFec_Fin.Text
                        .Numero_Personas = 0
                        .Numero_Dias = 0
                        .Costo_Persona = _
                        ObtenerPrecios(txtpreotros1.Text, txtpreotros2.Text, txtpreotros3.Text, _
                                       txtpreotros4.Text, txtpreotros5.Text)(i)
                        .Observaciones_Add = _
                        ObtenerMotivos(txtmototros1.Text, txtmototros2.Text, txtmototros3.Text, _
                                txtmototros4.Text, txtmototros5.Text)(i)
                        .Sub_Total = txtVerHerram.Text.Trim
                    End With
                Else
                    Continue For
                End If
            Else
                Continue For
            End If
            'GRABAR BEAN
            negocioAdicional.InsertarAdicional(beanAdicional)
        Next
        Dim script As String = "<script language=Javascript>"
        script += "alert('Se registró la requisición exitosamente');"
        script += "</script>"
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "script", script)
        Response.Redirect("Home.aspx")
    End Sub

    Private Function cargarRequisicion() As BE.RequisicionDTO
        Dim beanRequisicion As New BE.RequisicionDTO
        With beanRequisicion
            .Numero_Orden_Venta = txtOV.Text.Trim
            .Codigo_Estado_Documento = txtEstadoRequerimiento.Text.Trim
            .Fecha_Generada_Requision = txtFecha.Text.Trim
            .Total_Personas = txtTotPersonas.Text.Trim
            .Total_Dias = txtTotdias.Text.Trim
            .Total_Costo = txtTotRequirimiento.Text.Trim
            .Codigo_Servicio = ddlServicio.SelectedValue
            .Codigo_Tecnologia = ddlTecnologia.SelectedValue
            .Codigo_Usuario = Session("USUARIO")
            .Fecha_Inicio = txtFec_Ini.Text.Trim
            .Fecha_Fin = txtFec_Fin.Text.Trim
        End With
        Return beanRequisicion
    End Function
    '        Dim txt3 As New TextBox()
    '        With txt3
    '            .Attributes.Add("style", "margin-bottom: 3px")
    '            .Text = "Ingrese el Petróleo usado"
    '            .ID = "txtPetMotivo" + (QuantityPetro + 1).ToString()
    '            .Attributes.Add("onFocus", "this.value=''")
    '        End With
    Private Function ObtenerPrecioscbo(ByVal dias As String, ByVal pers As String, ByVal gasto As String) As Integer
        Dim subTot As Double = 0
        If Not String.IsNullOrEmpty(dias) Or String.IsNullOrEmpty(pers) Or String.IsNullOrEmpty(gasto) Then
            subTot = Double.Parse(dias) * Double.Parse(pers) * Double.Parse(gasto)
        End If
        Return subTot
    End Function
    Private Function ObtenerPreciossincbo(ByVal pr_cad As String, ByVal se_cad As String, _
                                          ByVal ter_cad As String, ByVal cua_cad As String, _
                                          ByVal quin_cad As String) As Double
        Dim subTot As Double = 0

        If Not String.IsNullOrEmpty(pr_cad) Or String.IsNullOrEmpty(se_cad) Or String.IsNullOrEmpty(ter_cad) Or _
               String.IsNullOrEmpty(cua_cad) Or String.IsNullOrEmpty(quin_cad) Then
            subTot = Double.Parse(pr_cad) + Double.Parse(se_cad) + Double.Parse(ter_cad) + _
                     Double.Parse(cua_cad) + Double.Parse(quin_cad)
        End If
        Return subTot
    End Function
    Private Function ObtenerDescripciones(ByVal pr_cad As String, ByVal se_cad As String, _
                                         ByVal ter_cad As String, ByVal cua_cad As String, _
                                         ByVal quin_cad As String) As List(Of String)
        Dim lista As New List(Of String)
        lista.Add(pr_cad)
        lista.Add(se_cad)
        lista.Add(ter_cad)
        lista.Add(cua_cad)
        lista.Add(quin_cad)
        Return lista
    End Function
    Private Function ObtenerPrecios(ByVal pr_cad As String, ByVal se_cad As String, _
                                    ByVal ter_cad As String, ByVal cua_cad As String, _
                                    ByVal quin_cad As String) As List(Of Double)
        Dim lista As New List(Of Double)
        lista.Add(Double.Parse(pr_cad))
        lista.Add(Double.Parse(se_cad))
        lista.Add(Double.Parse(ter_cad))
        lista.Add(Double.Parse(cua_cad))
        lista.Add(Double.Parse(quin_cad))
        Return lista
    End Function
    Private Function TotalRequisicion() As Double
        Dim total As Double = 0
        total = Double.Parse(txtVerAlim.Text.Trim) + Double.Parse(txtVerAloj.Text.Trim) + Double.Parse(txtVerFletes.Text.Trim) + Double.Parse(txtVerHerram.Text.Trim) + _
        Double.Parse(txtVerMovil.Text.Trim) + Double.Parse(txtVerOtros.Text.Trim) + Double.Parse(txtVerPasaj.Text.Trim) + _
        Double.Parse(txtVerPerso.Text.Trim) + Double.Parse(txtVerPetrol.Text.Trim)
        Return total
    End Function

    Private Function ObtenerMotivos(ByVal pri_cad As String, ByVal seg_cad As String, ByVal ter_cad As String, _
                             ByVal cua_cad As String, ByVal qui_cad As String) As List(Of String)
        Dim lista As New List(Of String)
        lista.Add(pri_cad)
        lista.Add(seg_cad)
        lista.Add(ter_cad)
        lista.Add(cua_cad)
        lista.Add(qui_cad)
        Return lista
    End Function

    Private Function ObtenerCargosPersonal(ByVal pri_cad As String, ByVal seg_cad As String, ByVal ter_cad As String, _
                             ByVal cua_cad As String, ByVal qui_cad As String, ByVal sex_cad As String) As List(Of String)
        Dim lista As New List(Of String)
        lista.Add(pri_cad)
        lista.Add(seg_cad)
        lista.Add(ter_cad)
        lista.Add(cua_cad)
        lista.Add(qui_cad)
        lista.Add(sex_cad)
        Return lista
    End Function
    Private Function ObtenerCantidadPersonal(ByVal pr_cad As String, ByVal se_cad As String, _
                                    ByVal ter_cad As String, ByVal cua_cad As String, _
                                    ByVal quin_cad As String, ByVal sex_cad As String) As List(Of Double)
        Dim lista As New List(Of Double)
        lista.Add(Double.Parse(pr_cad))
        lista.Add(Double.Parse(se_cad))
        lista.Add(Double.Parse(ter_cad))
        lista.Add(Double.Parse(cua_cad))
        lista.Add(Double.Parse(quin_cad))
        lista.Add(Double.Parse(sex_cad))
        Return lista
    End Function
    Private Function ObtenerNroDiasPersonal(ByVal pr_cad As String, ByVal se_cad As String, _
                                    ByVal ter_cad As String, ByVal cua_cad As String, _
                                    ByVal quin_cad As String, ByVal sex_cad As String) As List(Of Double)
        Dim lista As New List(Of Double)
        lista.Add(Double.Parse(pr_cad))
        lista.Add(Double.Parse(se_cad))
        lista.Add(Double.Parse(ter_cad))
        lista.Add(Double.Parse(cua_cad))
        lista.Add(Double.Parse(quin_cad))
        lista.Add(Double.Parse(sex_cad))
        Return lista
    End Function
    Private Function ObtenerPagoPersonal(ByVal pr_cad As String, ByVal se_cad As String, _
                                    ByVal ter_cad As String, ByVal cua_cad As String, _
                                    ByVal quin_cad As String, ByVal sex_cad As String) As List(Of Double)
        Dim lista As New List(Of Double)
        lista.Add(Double.Parse(pr_cad))
        lista.Add(Double.Parse(se_cad))
        lista.Add(Double.Parse(ter_cad))
        lista.Add(Double.Parse(cua_cad))
        lista.Add(Double.Parse(quin_cad))
        lista.Add(Double.Parse(sex_cad))
        Return lista
    End Function


    Sub CargarCargos()
        Dim capanegocios As New RequisicionBL
        Dim lista As New List(Of DropDownList)
        lista.Add(ddlCargoPers1)
        lista.Add(ddlCargoPers2)
        lista.Add(ddlCargoPers3)
        lista.Add(ddlCargoPers4)
        lista.Add(ddlCargoPers5)
        lista.Add(ddlCargoPers6)

        Try
            For i As Integer = 0 To lista.Count - 1
                With lista(i)
                    .DataSource = capanegocios.listarCargos
                    .DataValueField = "COD_CAR"
                    .DataTextField = "NOM_CAR"
                    .DataBind()
                End With
            Next
        Catch ex As Exception
            Dim str_error As String
            str_error = capanegocios.CapturaError
            Response.Redirect("Errores.aspx?par=" & str_error)
        Finally
            capanegocios = Nothing
        End Try
    End Sub

End Class



